#ifndef INET_ADDRESS_H
#define INET_ADDRESS_H

#include <netdb.h> 
#include <string> 
#include "types.h" 

class inet_address {
public:
    explicit inet_address(u16 port);
    inet_address(const std::string& ip, u16 port);
    explicit inet_address(const sockaddr_in &addr);

    const struct sockaddr *address() const {
        return static_cast<const struct sockaddr *>(&addr_);
    }
    const std::string& as_string() const { return full_; }
    const std::string& host() const { return host_; } 
    u16 port() const { return ntohs(addr_.sin_port); }

private:
    void set_string();

private:
    struct sockaddr_in addr_;
    std::string host_;          // host only
    std::string full_;          // full address as ip:port
};

#endif // INET_ADDRESS_H 
